<!-- eslint-disable vue/multi-word-component-names -->
<template>
  <div>
    <label for="all">全选:</label>
    <input type="checkbox" v-model="a" id="all" @click="quanxuan" />
    <ul>
      <li v-for="(item, i) in arr" :key="i">
        <input @click="xiao" type="checkbox" v-model="item.c" />
        <span>{{ item.name }}</span>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data () {
    return {
      arr: [
        { name: '猪八戒', c: false },
        { name: '孙悟空', c: false },
        { name: '唐僧', c: false },
        { name: '白龙马', c: false }
      ],

      a: null
    }
  },
  methods: {
    quanxuan (e) {
      // console.log(1);
      // console.log(e.target.checked);
      setTimeout(() => {
        this.arr.forEach(item => {

          item.c = e.target.checked

        })

      }, 0)
    },


    // 点击小的
    xiao () {
      //  如果全部点击了 就是true 再 v-model 设置给 大的
      setTimeout(() => {
        this.a = this.arr.every(item => item.c === true)

        // console.log(this.a)

      }, 0)

    }
  }
}
</script>
